// SPU管理接口
// 统一管理用户相关接口
import http from '@/utils/request'

import type { spuListAPIParamsType, spuResponseType, spuResponseTrademarkType, spuResponseImageType, spuResponseSaleType, spuResponseAllSaleType, spuDataType } from './type.ts'

// 通过枚举统一管理接口
enum API {
  SPULIST_URL = '/admin/product',
  ALLTRADEMARK_URL = '/admin/product/baseTrademark/getTrademarkList',
  IMAGE_URL = '/admin/product/spuImageList',
  SPUHASSALEATTR_URL = '/admin/product/spuSaleAttrList',
  SPUSALEATTR_URL = '/admin/product/baseSaleAttrList',
  ADDSPU_URL = '/admin/product/saveSpuInfo',
  UPDATESPU_URL = '/admin/product/updateSpuInfo',
  DELETESPU_URL = '/admin/product/deleteSpu',
}

// 获取spu表格数据
export const getSpuListAPI = ({page, limit, category3Id}: spuListAPIParamsType) => http.get<any, spuResponseType>(API.SPULIST_URL + `/${page}/${limit}`, {params: {category3Id}})

// 获取spu品牌数据
export const getSpuTrademarkAPI = () => http.get<any, spuResponseTrademarkType>(API.ALLTRADEMARK_URL)

// 获取spu下照片墙数据
export const getSpuImageAPI = (spuId: number | string) => http.get<any, spuResponseImageType>(API.IMAGE_URL + `/${spuId}`)

// 获取spu下已有的销售属性
export const getSpuHasSaleAttrAPI = (spuId: number | string) => http.get<any, spuResponseSaleType>(API.SPUHASSALEATTR_URL + `/${spuId}`)

// 获取spu全部的销售属性（颜色、尺码、版本）
export const getSpuSaleAttrAPI = () => http.get<any, spuResponseAllSaleType>(API.SPUSALEATTR_URL)

// 添加新的spu
export const addSpuAPI = (data: spuDataType) => http.post<any, any>(API.ADDSPU_URL, data)

// 更新已有的spu
export const saveSpuAPI = (data: spuDataType) => http.post<any, any>(API.UPDATESPU_URL, data)

// 删除spu
export const deleteSpuAPI = (id: string | number) => http.delete<any, any>(API.DELETESPU_URL + `/${id}`)
